<template>
	<view class="wrap">
		<!-- <view class="tab">
			<lrTabs :tabs="tabs" @change="change"></lrTabs>
		</view> -->
		<view style="background-color: #FFFFFF; position: sticky; top: 0;z-index: 2;">
			<view class='box-title'>
				<view v-for="(item,index) in tabs":key= 'index' class='title' :class="selectIndex==index?'title1':''" @click='selectText(index)'>
					<text>{{item.value}}</text>
					<text>(</text>
					<text>{{item.code}}</text>
					<text>)</text>
				</view>
			</view>
		</view>

		<view v-if="orderList.length > 0">

			<view class="item" style="margin: 32upx 0;border-radius: 8upx;padding: 32upx"
				v-for="(item, index) in orderList" :key="index" >
				
				<view class="text-line1">
					<view class="text-name1">{{filterNull(item.reserveTenantName)}}</view>
					<view class="text-value1">{{filterNull(item.arrivalStatusStr)}}</view>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line3">
					<text >预约品牌/车系: </text>
					<text >{{filterNull(item.brandName) + " " + filterNull(item.seriesName)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line3">
					<text >预约车型: </text>
					<text >{{filterNull(item.modelName)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line3">
					<text >预约人: </text>
					<text >{{filterNull(item.contact)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>

				<view class="text-line3">
					<text >联系电话: </text>
					<text >{{filterNull(item.phone)}}</text>
				</view>

				<u-line color="#EDEDED"></u-line>
				
				<view class="text-line3">
					<text >说明: </text>
					<text >{{filterNull(item.reserveContent)}}</text>
				</view>
				<view class="title-wrap" style="margin: 0;">

					<view class="title-warn">

					</view>

					<view class="btn-detail1" @click.stop="itemClick(item)">
						详情
					</view>
				</view>

			</view>

			<u-loadmore :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>

		<no-data v-else></no-data>


	</view>
</template>

<script>
	import {cluessourcedriverlist, cluessourcedrivercount} from '../../../common/api.js'
	import lrTabs from '../../../components/activity/lr-tabs.vue'

	export default {
		components: {
			lrTabs
		},
		data() {
			return {
				tabs: [{
						code: 0,
						value: '预约成功'
					},
					{
						code: 0,
						value: '已到店'
					},
					{
						code: 0,
						value: '无效'
					}
				],
				pageNo: 1,
				arrivalStatus: 1,//	1.预约成功 2.已到店 3.无效
				loadingStatus: 'loading',
				orderList: [],
				selectIndex:0,
			}
		},

		onLoad() {
			this.getData()
			this.getCount()
		},

		methods: {
			
			getCount(){
				cluessourcedrivercount().then(res=>{
					this.tabs[0].code = res.appointmentSucceededCount;
					this.tabs[1].code = res.arrivedStoreCount;
					this.tabs[2].code = res.invalidCount;
				})
			},
			
			getData() {
				cluessourcedriverlist ({
					params: {
						pageNo: this.pageNo,
						arrivalStatus:this.arrivalStatus
					}
				}).then(res => {
					if (this.pageNo == 1) {
						this.orderList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();

						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;

							this.loadingStatus = 'loadmore';
						} else {

							this.loadingStatus = 'nomore';
						}
					}

					if (!uni.$u.test.isEmpty(res)) {
						this.orderList = this.orderList.concat(res);
					}


				})
			},

			itemClick(item) {
				uni.navigateTo({
					url: './testdrive-orderdetail?cluesId='+item.cluesId
				})
			},

			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			},
			// tab栏切换
			selectText(index){
				this.arrivalStatus = index + 1;
				this.selectIndex = index
				this.pageNo = 1;
				this.getData();
			},
			change(index){
				this.arrivalStatus = index + 1;
				
				this.pageNo = 1;
				this.getData();
				
			}
		},

		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},

		onReachBottom() {
			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		@include flex(column);
		height: calc(100vh - var(--window-top));
		padding: 32upx;
		.box-title{
			width: 100%;
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-bottom: 24upx;
			background-color: #FFFFFF; 
			border-radius: 8upx;
			.title{
				text-align: center;
				text{
					width:200upx;
					font-size: 28upx;
					color:#000000;
				}
			}
			.title1{
				background-color: #173B42 ;
				color:#ffffff;
				border-radius: 8upx;
				text{
					color:#ffffff;
				}
			}
		} 
		.btn-detail1{
			font-size: 28upx;
			color:#173B42 ;
			padding:12upx 32upx;
			border:1upx solid #173B42 ;
			border-radius: 4upx;
		}
		.text-line1{
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom:32upx;
			.text-name1{
				font-size: 32upx;
				color:#000000;
				font-weight: bold;
			}
			.text-value1{
				font-size: 28upx;
				color:#469428 ;
			}
		}
		.text-line3{
			// display: flex;
			// justify-content: flex-start;	
			// align-items: center;
			margin-bottom: 16upx;
			text{
				font-size:24upx;
				color:#666666;
			}
			
		}
	}
	

	.title-wrap {
		display: inline-flex;
		justify-content: space-between;
	}

	.title-warn {
		color: #E93131;
		background-color: #FFFFFF;
		white-space: nowrap;
		text-align: center;
		font-size: 26upx;
		line-height: 60upx;
		margin: 10upx 0upx;
		align-self: flex-end;
	}
	.title {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 28upx;
		color: $black33;
		margin-left: 20upx;
	}
</style>
